home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Syn Text Editor 2.1.0.46 / synsetup-2.1.0.46.exe / {app} / scripts / cvs.vbs < prev    next >
Text File  |  2003-08-13  |  9KB  |  299 lines

  1. ' Caption: CVS|
  2. ' Hint: Do some CVS actions|
  3. ' Icon: cvs.ico|
  4. '
  5. '  syn
  6. '  Copyright (C) 2000-2003, Ascher Stefan. All rights reserved.
  7. '  stievie@utanet.at, http://web.utanet.at/ascherst/
  8. '
  9. '  The contents of this file are subject to the Mozilla Public License
  10. '  Version 1.1 (the "License"); you may not use this file except in compliance
  11. '  with the License. You may obtain a copy of the License at
  12. '  http://www.mozilla.org/MPL/
  13. '
  14. '  Software distributed under the License is distributed on an "AS IS" basis,
  15. '  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  16. '  the specific language governing rights and limitations under the License.
  17. '
  18. '  The Original Code is cvs.vbs, released Sun, 28 Jul 2002 14:06:54 UTC.
  19. '
  20. '  The Initial Developer of the Original Code is Ascher Stefan.
  21. '  Portions created by Ascher Stefan are Copyright (C) 2000-2003 Ascher Stefan.
  22. '  All Rights Reserved.
  23. '
  24. '  Contributor(s): .
  25. '
  26. '  Alternatively, the contents of this file may be used under the terms of the
  27. '  GNU General Public License Version 2 or later (the "GPL"), in which case
  28. '  the provisions of the GPL are applicable instead of those above.
  29. '  If you wish to allow use of your version of this file only under the terms
  30. '  of the GPL and not to allow others to use your version of this file
  31. '  under the MPL, indicate your decision by deleting the provisions above and
  32. '  replace them with the notice and other provisions required by the GPL.
  33. '  If you do not delete the provisions above, a recipient may use your version
  34. '  of this file under either the MPL or the GPL.
  35. '
  36. '  You may retrieve the latest version of this file at the syn home page,
  37. '  located at http://syn.sourceforge.net/
  38. '
  39. ' $Id: cvs.vbs,v 1.8.2.5 2003/08/13 00:38:45 neum Exp $
  40. '
  41.  
  42. ' This Script should provide a *very* simple integration from CVS (Concurrent
  43. ' Version System), and it's in a very exerimental state. It seems to work with
  44. ' local repositories, and with the server from SourceForge.
  45.  
  46. ' ScriptEngine=VBScript
  47.  
  48. option explicit
  49.  
  50. ' Remove the dot to include this file(s)
  51. '#include <consts>
  52. '#include <cmnfunc>
  53. const RegKey = "HKCU\Software\Ascher\syn\Macros"
  54.  
  55. dim okbutton
  56. dim cancelbutton
  57. dim msgmemo
  58. dim cleancopy
  59.  
  60. sub MemoEnter(Sender)
  61.   okbutton.Default = false
  62. end sub
  63. sub MemoExit(Sender)
  64.   okbutton.Default = true
  65. end sub
  66. sub ComboClick(Sender)
  67.   msgmemo.Enabled = (Sender.ItemIndex = 1)
  68.   if msgmemo.Enabled then
  69.     msgmemo.Color = 5 or &h80000000     ' clWindow
  70.   else
  71.     msgmemo.Color = 15 or &h80000000    ' clBtnFace
  72.   end if
  73.   cleancopy.Enabled = (Sender.ItemIndex = 0)
  74. end sub
  75.  
  76. sub Main(FileName)
  77.   if (Documents.Count = 0) then
  78.     MsgBox "There is currently no file open.", vbCritical
  79.     exit sub
  80.   end if
  81.   if not CheckSave then
  82.     exit sub
  83.   end if
  84.  
  85.   dim form
  86.   form = Create("TForm", Self)
  87.   with form
  88.     .Caption = "CVS"
  89.     .Position = "poOwnerFormCenter"
  90.     .BorderStyle = "bsDialog"
  91.     .Height = 400
  92.     .Width = 350
  93.   end with
  94.   dim cbo
  95.   cbo = Create("TComboBox", Self)
  96.   with cbo
  97.     .Parent = form
  98.     .Top = 20
  99.     .Left = 5
  100.     .Width = form.ClientWidth - 10
  101.     .Style = "csDropDownList"
  102.     .Items.Add "Update"
  103.     .Items.Add "Commit"
  104.     .Items.Add "Add"
  105.     .Items.Add "Remove"
  106.     .Items.Add "Diff"
  107.     .ItemIndex = 0
  108.     .OnClick = "ComboClick"
  109.   end with
  110.   with Create("TLabel", Self)
  111.     .Parent = form
  112.     .Caption = "&Do what:"
  113.     .Top = cbo.Top - 15
  114.     .Left = 5
  115.     .FocusControl = cbo
  116.   end with
  117.   
  118.   dim list
  119.   dim rootdir
  120.   dim ii
  121.  
  122.   rootdir = AddBackSlash(ExtractFilePath(ActiveDocument.FileName))
  123.  
  124.   dim cvsroot
  125.   dim rootfile
  126.   dim reposfile
  127.   dim repository
  128.   rootfile = AddBackSlash(rootdir) & "CVS\Root"
  129.   if FileExists(rootfile) then
  130.     cvsroot = FileReadLine(rootfile, 0)
  131.   end if
  132.   reposfile = AddBackSlash(rootdir) & "CVS\Repository"
  133.   if FileExists(reposfile) then
  134.     repository = FileReadLine(reposfile, 0)
  135.   end if
  136.  
  137.   ii = InStr(1, repository, "/")
  138.   if ii > 0 then
  139.     repository = Mid(repository, ii, Len(repository) - ii)
  140.     rootdir = Mid(rootdir, 1, Len(rootdir) - Len(repository) - 1)
  141.   end if
  142.  
  143.   list = Create("TCheckListBox", Self)
  144.   with list
  145.     .Parent = form
  146.     .Left = 5
  147.     .Top = 60
  148.     .Height = form.ClientHeight - 250
  149.     .Width = form.ClientWidth - 10
  150.     dim i, j
  151.     for i = 0 to Documents.Count - 1
  152.       if Documents(i).FileName <> "" then
  153.         if InStr(1, Documents(i).FileName, rootdir) > 0 then
  154.           j = .Items.Add(Mid(Documents(i).FileName, Len(rootdir) + 1))
  155.           .Checked(j) = true
  156.         end if
  157.       end if
  158.     next
  159.   end with
  160.   
  161.   with Create("TLabel", Self)
  162.     .Parent = form
  163.     .Caption = "&Select files:"
  164.     .Top = list.Top - 15
  165.     .Left = 5
  166.     .FocusControl = list
  167.   end with
  168.   msgmemo = Create("TMemo", Self)
  169.   with msgmemo
  170.     .Parent = form
  171.     .Top = list.Top + list.Height + 20
  172.     .Left = 5
  173.     .Height = form.ClientHeight - .Top - 80
  174.     .Width = form.ClientWidth - 10
  175.     .ScrollBars = "ssVertical"
  176.     .WantReturns = true
  177.     .WantTabs = false
  178.     .OnEnter = "MemoEnter"
  179.     .OnExit = "MemoExit"
  180.     .Enabled = false
  181.     .Color = 15 or &h80000000
  182.   end with
  183.   with Create("TLabel", Self)
  184.     .Parent = form
  185.     .Caption = "&Message:"
  186.     .Top = msgmemo.Top - 15
  187.     .Left = 5
  188.     .FocusControl = msgmemo
  189.   end with
  190.  
  191.   dim compress
  192.   compress = Create("TSpinEdit", Self)
  193.   with compress
  194.     .Parent = form
  195.     .Top = msgmemo.Top + msgmemo.Height + 20
  196.     .Left = 5
  197.     .ShowHint = true
  198.     .Hint = "0 = no compression"
  199.     .MinValue = 0
  200.     .MaxValue = 9
  201.     .Value = RegGetSettings(AddBackslash(RegKey) & "cvs_compression", 3)
  202.   end with
  203.   with Create("TLabel", Self)
  204.     .Parent = form
  205.     .Caption = "&Compression:"
  206.     .Top = compress.Top - 15
  207.     .Left = 5
  208.     .FocusControl = compress
  209.   end with
  210.  
  211.   cleancopy = Create("TCheckBox", Self)
  212.   with cleancopy
  213.     .Parent = form
  214.     .Caption = "&Get clean copy"
  215.     .Top = msgmemo.Top + msgmemo.Height + 20
  216.     .Left = 150
  217.   end with
  218.   
  219.   okbutton = Create("TButton", Self)
  220.   with okbutton
  221.     .Parent = form
  222.     .Caption = "OK"
  223.     .Default = true
  224.     .Left = form.ClientWidth - (.Width + 5) * 2
  225.     .Top = form.ClientHeight - .Height - 5
  226.     .ModalResult = mrOK
  227.   end with
  228.   cancelbutton = Create("TButton", Self)
  229.   with cancelbutton
  230.     .Parent = form
  231.     .Caption = "Cancel"
  232.     .Cancel = true
  233.     .Left = form.ClientWidth - .Width - 5
  234.     .Top = form.ClientHeight - .Height - 5
  235.     .ModalResult = mrCancel
  236.   end with
  237.  
  238.   if (cvsroot = "") or (repository = "") then
  239.     MsgBox "One or more of the following files does not exist:" & vbCrLf & rootfile & vbCrLf & reposfile, vbCritical
  240.   else
  241.     if form.ShowModal = mrOK then
  242.     
  243.       SetEnv "CVSROOT", cvsroot
  244.       if InStr(1, cvsroot, ":ext:") > 0 then
  245.         SetEnv "CVS_RSH", "ssh"
  246.       elseif InStr(1, cvsroot, ":pserver:") > 0 then
  247.         SetEnv "CVS_RSH", ""       ' <- ???
  248.       elseif InStr(1, cvsroot, ":local:") > 0 then
  249.         SetEnv "CVS_RSH", ""
  250.       end if
  251.       
  252.       dim msg, files
  253.       if msgmemo.Lines.Text = "" then
  254.         msg = AddQuotes("No message")
  255.       else
  256.         msg = AddQuotesUnless(Replace(msgmemo.Lines.Text, vbCrLf, "\n"))
  257.       end if
  258.       
  259.       for j = 0 to list.Items.Count - 1
  260.         if list.Checked(j) then
  261.           files = files & " " & AddQuotesUnless(list.Items(j))
  262.         end if
  263.       next
  264.       if files <> "" then
  265.       
  266.         dim comp
  267.         if compress.Value > 0 then comp = "-z" & CStr(compress.Value) & " "
  268.         if (compress.Value <= 9) and (compress.Value >= 0) then
  269.           RegSetSettings AddBackslash(RegKey) & "cvs_compression", compress.Value
  270.         end if
  271.  
  272.         dim args
  273.         select case cbo.ItemIndex
  274.         case 0
  275.           if cleancopy.Checked then
  276.             args = comp & "update -dPC" & files
  277.           else
  278.             args = comp & "update -dP" & files
  279.           end if
  280.         case 1
  281.           args = comp & "commit" & " -m " & msg & files
  282.         case 2
  283.           args = comp & "add" & files
  284.         case 3
  285.           args = comp & "remove" & files
  286.         case 4
  287.           args = comp & "diff" & files
  288.         end select
  289.       end if
  290.       dim pdir
  291.       pdir = CurDir
  292.       CurDir = rootdir
  293.       Execute "cvs " & args, 1, false
  294.       CurDir = pdir
  295.     end if
  296.   end if
  297.   form.Free
  298. end sub
  299.